package com.ziyun.erp.modules.goods.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ziyun.erp.modules.goods.dao.GoodsBrandDao;
import com.ziyun.erp.modules.goods.entity.GoodsBrandEntity;
import com.ziyun.erp.modules.goods.service.GoodsBrandService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("goodsBrandService")
public class GoodsBrandServiceImpl extends ServiceImpl<GoodsBrandDao, GoodsBrandEntity> implements GoodsBrandService {

    @Override
//    @DataSource(name = DataSourceNames.SECOND)
    public PageUtils queryPage(Map<String, Object> params) {
        Integer brandId = StringUtil.getRequestParamInteger(params.get("brandId"));
        String brandName = StringUtil.getRequestParamString(params.get("brandName"));
        Integer sellerId = StringUtil.getRequestParamInteger(params.get("seller_id"));
        Page<GoodsBrandEntity> page = this.selectPage(
                new Query<GoodsBrandEntity>(params).getPage(),
                new EntityWrapper<GoodsBrandEntity>()
                .eq("disabled","false")
                .eq(brandId != null,"brand_id",brandId)
                        .eq(sellerId != null,"seller_id",sellerId)
                .like(StringUtils.isNotBlank(brandName),"brand_name",brandName)
        );

        return new PageUtils(page);
    }

}
